﻿using easy_ccms.core;

namespace easyccms.WebUI.Code
{
    public class ApplicationSettings
    {

        #region Fields

        /// <summary>
        /// Root node of settings document.
        /// </summary>
        private const string RootNode = "WebSite";

        /// <summary>
        /// Basic xml manager to provide get set settings.
        /// </summary>
        private readonly BasicXmlManager _xmlManager;
        #endregion
        #region constructors
        /// <summary>
        /// Initializes a new instance of the <see cref="ApplicationSettings"/> class.
        /// </summary>
        public ApplicationSettings()
        {
            this._xmlManager = new BasicXmlManager(easyccms.WebUI.Properties.Settings.Default.SettingsFileName,"~");
        }

        #endregion
        #region Properties
        #region General


        /// <summary>
        /// Gets or sets a value indicating whether this <see cref="ApplicationSettings"/> is online.
        /// </summary>
        /// <value>
        ///   <c>true</c> if online; otherwise, <c>false</c>.
        /// </value>
        public bool Online
        {
            get
            {
                if (this._xmlManager.GetStringValue(RootNode, "General", "Online").ToLower() == "true")
                    return true;
                else
                    return false;
            }
            set { this._xmlManager.UpdateElementValue(RootNode, "General", "Online", (value ? "True" : "False")) ; }
        }

        /// <summary>
        /// Gets or sets the offline page.
        /// </summary>
        /// <value>
        /// The offline page.
        /// </value>
        public string OfflinePage
        {
            get { return this._xmlManager.GetStringValue(RootNode, "General", "OfflinePage"); }
            set { this._xmlManager.UpdateElementValue(RootNode, "General", "OfflinePage", value); }
        }

        #endregion

        #region Settings

        /// <summary>
        /// Gets or sets the name of the website.
        /// </summary>
        /// <value>
        /// The name of the website.
        /// </value>
        public string WebsiteName
        {
            get { return this._xmlManager.GetStringValue(RootNode, "Settings", "WebsiteName"); }
            set { this._xmlManager.UpdateElementValue(RootNode, "Settings", "WebsiteName", value); }
        }

        /// <summary>
        /// Gets or sets the website logo.
        /// </summary>
        /// <value>
        /// The website logo.
        /// </value>
        public string WebsiteLogo
        {
            get { return this._xmlManager.GetStringValue(RootNode, "Settings", "WebsiteLogo"); }
            set { this._xmlManager.UpdateElementValue(RootNode, "Settings", "WebsiteLogo", value); }
        }

        /// <summary>
        /// Gets or sets the administrator email.
        /// </summary>
        /// <value>
        /// The administrator email.
        /// </value>
        public string AdministratorEmail
        {
            get { return this._xmlManager.GetStringValue(RootNode, "Settings", "AdministratorEmail"); }
            set { this._xmlManager.UpdateElementValue(RootNode, "Settings", "AdministratorEmail", value); }
        }

        #endregion

        #region EmailSettings

        /// <summary>
        /// Gets or sets the server.
        /// </summary>
        /// <value>
        /// The server.
        /// </value>
        public string Server
        {
            get { return this._xmlManager.GetStringValue(RootNode, "EmailSettings", "Server"); }
            set { this._xmlManager.UpdateElementValue(RootNode, "EmailSettings", "Server", value); }
        }

        /// <summary>
        /// Gets or sets the name of the user.
        /// </summary>
        /// <value>
        /// The name of the user.
        /// </value>
        public string UserName
        {
            get { return this._xmlManager.GetStringValue(RootNode, "EmailSettings", "UserName"); }
            set { this._xmlManager.UpdateElementValue(RootNode, "EmailSettings", "UserName", value); }
        }

        /// <summary>
        /// Gets or sets the password.
        /// </summary>
        /// <value>
        /// The password.
        /// </value>
        public string Password
        {
            get { return this._xmlManager.GetStringValue(RootNode, "EmailSettings", "Password"); }
            set { this._xmlManager.UpdateElementValue(RootNode, "EmailSettings", "Password", value); }
        }

        #endregion
        #endregion
    }
}